//
//  BCUserInfoHeadPortraitCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/27.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCUserInfoHeadPortraitCell.h"

#import "BCUserCenterHeaderView.h"

@interface BCUserInfoHeadPortraitCell ()

@property (nonatomic, strong) BCUserCenterHeaderImageButton *headerImageButton;

@end

@implementation BCUserInfoHeadPortraitCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    CGSize headerImageButtonSize = [BCUserCenterHeaderImageButton defaultSize];
    self.headerImageButton = [BCUserCenterHeaderImageButton new];
    [self addSubview:self.headerImageButton];
    [self.headerImageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(headerImageButtonSize);
        make.right.mas_equalTo(self.contentView).offset(-15.0);
    }];
    [self.headerImageButton addTarget:self action:@selector(headerImageButtonDidClickedAction) forControlEvents:UIControlEventTouchUpInside];
}



- (void)setCellModel:(BCUserInfoCellModel *)cellModel {
    [super setCellModel:cellModel];
    UserInfoModel *userInfo = [BCUserManager sharedUser].userInfo;
    //
    [self.headerImageButton.headerIV sd_setImageWithURL:[NSURL URLWithString:userInfo.head_img] placeholderImage:nil];
}

#pragma mark - headerImageButtonDidClickedAction
- (void)headerImageButtonDidClickedAction {
    if (self.tableView) {
        if (self.tableView.delegate && [self.tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
            [self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[self.tableView indexPathForCell:self]];
        }
    }
}



+ (CGFloat)defaultHeight {
    return [BCUserCenterHeaderImageButton defaultSize].height+20.0;
}

@end
